﻿using System;
using System.Collections.Generic;
using System.Data;
using WebProject.Core.Models;
using WebProject.Core.Repositories;

namespace WebProject.Core.Service
{
    public class ProductionTypeService : IProductionTypeService
    {
        #region[Private Attribute]
        private readonly IProductionTypeRepository m_ProductionTypeRepository;
        #endregion

        #region[Constructor]
        public ProductionTypeService(IProductionTypeRepository productionTypeRepository)
        {
            if (productionTypeRepository == null)
            {
                throw new ArgumentNullException("productionTypeRepository");
            }
            m_ProductionTypeRepository = productionTypeRepository;
        }
        #endregion

        #region[Implement Methods]
        public int Add(ProductionType productionType)
        {
            if (productionType == null)
            {
                throw new ArgumentNullException("productionType");
            }
            return m_ProductionTypeRepository.Add(productionType);
        }

        public bool Remove(ProductionType productionType)
        {
            if (productionType == null)
            {
                throw new ArgumentNullException("productionType");
            }
            return m_ProductionTypeRepository.Remove(productionType) != 0;
        }

        public bool Remove(int id)
        {
            var target = m_ProductionTypeRepository.GetById(id);
            if (target == null)
            {
                throw new ObjectNotFoundException(string.Format("Target ProductionType with Id={0} not found", id));
            }
            return m_ProductionTypeRepository.Remove(target) != 0;
        }

        public bool Update(ProductionType productionType)
        {
            if (productionType == null)
            {
                throw new ArgumentNullException("productionType");
            }
            return m_ProductionTypeRepository.Update(productionType) != 0;
        }

        public IList<ProductionType> GetAllType()
        {
            return m_ProductionTypeRepository.GetAll();
        }

        public ProductionType GetTypeById(int id)
        {
            return m_ProductionTypeRepository.GetById(id);
        }
        #endregion
    }
}